<?php

namespace App\Admin\Extensions;

use Encore\Admin\Form\Field;

class Useditor extends Field
{
    protected $view = 'admin.useditor';

    protected static $css = [
    ];

    protected static $js = [
        'packages/ueditor/ueditor.config.js',
        'packages/ueditor/ueditor.all.js',
    ];

    public function render()
    {
        $name = $this->formatName($this->column);

        $this->script = <<<EOT
        UE.delEditor('{$name}er');
        var ue{$name} = UE.getEditor('{$name}er'); // 默认id是ueditor
        ue{$name}.ready(function () {
            ue{$name}.execCommand('serverparam', '_token', '{{ csrf_token() }}');
        });
        $('form').submit(function (){
            $('input[name={$name}]').val(ue{$name}.getContent())
            return true
        })
EOT;
        return parent::render();
    }
}